let portToCnt = null;
let actived = true;

browser.runtime.onConnect.addListener((p) => {
  portToCnt = p;
  portToCnt.postMessage({ changeNow: actived, userAction: false });
});

browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.checkStatus) {
    sendResponse({ status: actived });
  } else if (request.switchStatus) {
    actived = !actived;
    sendResponse({ status: actived });
    portToCnt && portToCnt.postMessage({ changeNow: true, userAction: true });
  }
});
